<?php

namespace app\index\controller;

use think\Request;
use think\Validate;
use app\index\model\Group as GroupModel;

class Group extends Base
{
    public function _initialize()
    {
        parent::_initialize();
    }

    public function save()
    {
        $validate = new Validate([
            'name'  => 'require|max:16',
        ]);
        $data = input('post.');
        if (! $validate->check($data)) {
            $this->error($validate->getError());
            return ;
        }

        $group = new GroupModel($data);
        $group->allowField(true)->save();
        $this->success('成功');
    }

    public function selected()
    {
        $ids = input('post.')['ids'];
        GroupModel::setSelected($ids);

        $this->success('设置成功');
    }

    public function update(Request $request, $id)
    {

    }

    public function delete($id)
    {

    }
}
